package com.zbkj.service.model.front.req.fund;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import com.zbkj.dal.base.enums.CrabRoeTradeType;
import com.zbkj.dal.pojo.request.PageParamRequest;
import com.zbkj.service.util.DateTimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;

@Data
@ApiModel
@EqualsAndHashCode(callSuper = true)
public class CrabRoeFundFlowReq extends PageParamRequest {

    @ApiModelProperty(value = "查询月份", required = false, example = "2024-01")
    private String month;

    /**
     * @see com.zbkj.dal.base.enums.FundDirectionEnums
     */
    @ApiModelProperty(value = "收支类型【2:支出/1:收入】", required = false, example = "1")
    private Integer tradeDirection;

    /**
     * @see CrabRoeTradeType
     */
    @ApiModelProperty(value = "交易类型【RECOMMEND】", required = false, example = "RECOMMEND")
    private String tradeType;

    @ApiModelProperty(value = "是否冻结：0-否/1-是", required = false, example = "1")
    private Integer frozen;

    public Integer monthBegin() {
        if (StringUtils.isBlank(month)) {
            return DateTimeUtil.monthBeginInt();
        }
        return Integer.valueOf(LocalDateTimeUtil.format(DateTimeUtil.monthBeginDate(month), DatePattern.PURE_DATE_PATTERN));
    }

    public Integer monthEnd() {
        if (StringUtils.isBlank(month)) {
            return Integer.valueOf(LocalDateTimeUtil.format(LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()), DatePattern.PURE_DATE_PATTERN));
        }
        return Integer.valueOf(LocalDateTimeUtil.format(DateTimeUtil.monthEndDate(month), DatePattern.PURE_DATE_PATTERN));
    }

}